﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SimpleSurvival.src
{
    //-----------------------------------------------//
    //INTERFACE - ITerrainTile.cs
    //-----------------------------------------------//
    public interface ITerrainTile
    {
        bool IsPathable { set; get; }
        bool IsWater { set; get; }
        int Height { set; get; }
        Point IndexedPosition { get; }
        IEntity Entity {get; }
    }

    //-----------------------------------------------//
    //CLASS - TerrainTile.cs
    //-----------------------------------------------//
    //Background Tiles
    public class TerrainTile : Entity, ITerrainTile
    {
        // Size of terrain tiles
        const int TILE_SIZE = 32;   //externalise
        bool _isPathable = true;

        public bool IsPathable
        {
            get { return _isPathable; }
            set { _isPathable = value; }
        }

        public IEntity Entity { get { return (IEntity)(this); } }

        bool _isWater = false;

        public bool IsWater
        {
            get { return _isWater; }
            set { _isWater = value; }
        }
        int _height = 0;

        //Height of the tile
        public int Height
        {
            get { return _height; }
            set { _height = value; }
        }


        //Indexed position is the tile position / tile size
        public Point IndexedPosition
        {
            get { return new Point((int)Entity.X / TILE_SIZE, (int)Entity.Y / TILE_SIZE); }
        }

        // Loads init values from EntityDefinitions
        public TerrainTile(int x, int y, string name, Map m, EntityDrawer ed, EntityDefinitions defs)
            : base(name, new SwinGame.Vector { X = x * TILE_SIZE, Y = y * TILE_SIZE },m,ed,defs)
        {
            _isWater = (defs.GetEntityDefValue(name,
                EntityDefinitions.FieldName.TERRAIN_ISWATER) == "TRUE");

            _isPathable = (defs.GetEntityDefValue(name,
                EntityDefinitions.FieldName.TERRAIN_PATHABLE) == "TRUE");
        }
    }
}
